package cn.edu.hqu.javaee.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import cn.edu.hqu.javaee.domain.Ingredient;
import cn.edu.hqu.javaee.domain.Taco;
<<<<<<< HEAD
import cn.edu.hqu.javaee.domain.User;
=======
>>>>>>> 3edfb768830aad65280760d8840187b9a62356fb
import cn.edu.hqu.javaee.domain.Order;
import cn.edu.hqu.javaee.repository.IngredientRepository;
import cn.edu.hqu.javaee.repository.OrderRepository;
import cn.edu.hqu.javaee.repository.TacoRepository;
<<<<<<< HEAD
import cn.edu.hqu.javaee.domain.User;
import cn.edu.hqu.javaee.repository.UserRepository;
=======
>>>>>>> 3edfb768830aad65280760d8840187b9a62356fb
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Controller
@RequestMapping("/result")
public class ResultController {
	private final IngredientRepository ingredientRepo;
	private OrderRepository orderRepo;
	private TacoRepository tacoRepo;
<<<<<<< HEAD
	private UserRepository userRepo;
	
	@Autowired
	public ResultController(IngredientRepository ingredientRepo,OrderRepository orderRepo,TacoRepository tacoRepo,
			UserRepository userRepo
=======
	
	@Autowired
	public ResultController(
			IngredientRepository ingredientRepo,
			OrderRepository orderRepo,
			TacoRepository tacoRepo
>>>>>>> 3edfb768830aad65280760d8840187b9a62356fb
			) {
		this.ingredientRepo = ingredientRepo;
		this.orderRepo = orderRepo;
		this.tacoRepo = tacoRepo;
<<<<<<< HEAD
		this.userRepo = userRepo;
=======
>>>>>>> 3edfb768830aad65280760d8840187b9a62356fb
	}
	
	@GetMapping
	public String showResult(Model model) {
		List <Order> orders = new ArrayList<>();
<<<<<<< HEAD
		List <User> user = new ArrayList<>();
		orderRepo.findAll().forEach(i -> orders.add(i));
		userRepo.findAll().forEach(i->user.add(i));
		model.addAttribute("orders",orders);
		model.addAttribute("user",user);
		log.info("orders: "+orders);
		log.info("user: "+user);
		System.out.println(user);
=======
		orderRepo.findAll().forEach(i -> orders.add(i));
		model.addAttribute("orders",orders);
		log.info("orders: "+orders);
>>>>>>> 3edfb768830aad65280760d8840187b9a62356fb
		return "result"; 
	}
	
}